package com.example.common.model

import com.example.common.api.BaseApiServer
import com.example.network.HttpInterceptorType
import com.example.network.HttpManager
import com.example.network.TokenInterceptorApiServer

open class BaseRepository<T :BaseApiServer> {

    private var tokenAPiServer:T ?= null
    private var uploadApiServer:T ?= null
    private var signApiServer:T ?= null
    private var commonApiServer:T ?= null

    fun <T>createApiServer(clazz :Class<*>,type:HttpInterceptorType):T{
        if (type==HttpInterceptorType.TOKEN){
            if (tokenAPiServer==null){
                tokenAPiServer=HttpManager.createApi(clazz, type)
            }
            return tokenAPiServer as T
        }

        if (type==HttpInterceptorType.SIGN){
            if (signApiServer==null){
                signApiServer=HttpManager.createApi(clazz, type)
            }
            return signApiServer as T
        }

        if (type==HttpInterceptorType.UPLOAD){
            if (uploadApiServer==null){
                uploadApiServer=HttpManager.createApi(clazz, type)
            }
            return uploadApiServer as T
        }

        if (type==HttpInterceptorType.INTERFACE){
            if (commonApiServer==null){
                commonApiServer=HttpManager.createApi(clazz, type)
            }
            return commonApiServer as T
        }

        return HttpManager.createApi(clazz, type) as T
    }

}